package com.example.adf.controller;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    @Cacheable(value = "spring.cache", key = "#username+#password")
    public String login(String username, String password) {
        //非空校验
        if(!StringUtils.hasLength(username) || !StringUtils.hasLength(password)) {
            return "参数错误";
        }
        return "缓存成功";
    }

    @RequestMapping("/del")
    @CacheEvict(value = "spring.cache", key = "#username+#password")
    public String del(String username, String password) {
        return "缓存删除";
    }

}

